<template>


    <div style="height:100%">
        <div style="padding:30px;">
            <el-button type="primary">
                <router-link to="/admin/subone/problemadd" tag="span">添加问题</router-link>
            </el-button>
            <br>
            <br>

            <div>
                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item label="标题">
                        <el-input v-model="formInline.title" placeholder="搜索标题"></el-input>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>

            <el-table
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        fixed
                        prop="title"
                        label="标题"
                        width="350">
                </el-table-column>

                <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
                        <router-link :to="{name:'problemsave',params:{id:scope.row.id}}">修改</router-link>
                    </template>
                </el-table-column>
            </el-table>

            <br>
            <el-pagination
                    background
                    :page-size="30"
                    layout="prev, pager, next"
                    :current-page="currentPage"
                    @current-change="handleCurrentChange"
                    :total="total">
            </el-pagination>
        </div>
    </div>

</template>

<script>
    export default {
        mounted() {

            axios.post('/api/getproblemlist').then(rew=>{
                this.tableData = rew.data.data
            })
        },
        methods: {
            onSubmit() {
                console.log(this.formInline);
                //搜索对应题目
                //章节分类
                axios.post('/api/SubOneSearch',this.formInline).then(rew=>{
                    //表格的数据赋值
                    this.tableData = rew.data.data
                    //页码数据赋值
                    this.total = rew.data.total
                })
            },
            handleClick(row) {
                this.$confirm('是否删除该题目?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post('/api/problemdel', row).then(rew => {
                        var index = this.tableData.indexOf(row)
                        this.tableData.splice(index, 1);
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleCurrentChange(currentPage) {
                let  page={
                    page: currentPage
                }
                axios.post('subone/getlist', page).then(rew => {
                    this.tableData = rew.data.data
                    this.total = rew.data.total
                })
            },
            hand(val, id) {
                let data = {
                    is_zy: val,
                    id: id
                }
                axios.post('/zy', data).then(rew => {
                })
            },
            ycthand(val, id) {
                let data = {
                    is_yct: val,
                    id: id
                }
                axios.post('/yc', data).then(rew => {

                })
            }
        },
        data() {
            return {
                chapters:'',
                tableData: [],
                currentPage: 1,
                total:0,
                formInline: {
                    title: '',
                    chapters_id: ''
                }
            }
        }
    }
</script>
<style scoped>

</style>